import Vue from 'vue'
import VueRouter from 'vue-router'
import { getToken, getUserInfo } from '@/utils/token'
Vue.use(VueRouter)
const routes = [
	{
		path: '/',
		name: 'index',
		component: () => import(/* webpackChunkName: "index" */ '../views/Index.vue')
	},
	{
		path: '/question',
		name: 'question',
		component: () => import(/* webpackChunkName: "question" */ '../views/Question.vue')
	},
	{
		path: '/detail',
		name: 'detail',
		component: () => import(/* webpackChunkName: "detail" */ '../views/Detail.vue')
	},
	{
		path: '/detail1',
		name: 'detail1',
		component: () => import(/** webpackChunkName: "detail1" */ '../views/Detail1.vue')
	},
	{
		path: '/detail2',
		name: 'detail2',
		component: () => import(/** webpackChunkName: "detail2" */ '../views/Detail2.vue')
	},
	{
		path: '/detail3',
		name: 'detail3',
		component: () => import(/** webpackChunkName: "detail3" */ '../views/Detail3.vue')
	},
	{
		path: '/detail4',
		name: 'detail4',
		component: () => import(/** webpackChunkName: "detail4" */ '../views/Detail4.vue')
	},
	{
		path: '/detail5',
		name: 'detail5',
		component: () => import(/** webpackChunkName: "detail5" */ '../views/Detail5.vue')
	}
]

const router = new VueRouter({
	routes,
	scrollBehavior () {
		return { x: 0, y: 0 }
	}
})
router.beforeEach((to, from, next) => {
	let list = ['/question', '/detail']
	if (list.includes(to.path)) {
		if(getToken() && getUserInfo()) {
			next();
		} else {
			next();
		}
	} else {
		next();
	}
})
export default router
